import { HOST } from "../../config/dev"

export const GET = (url, params={}) =>{
  let headers =  {
    Accept: 'application/json',
    'Content-Type': 'application/json'
  }
  if (params.token) {
    headers = {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'Authorization': 'JWT ' + params.token
    }
  }
  return fetch(HOST+url, {
    method: 'GET',
    headers
  }).then(res=>res.json())
} 
export const POST = (url, params) => fetch(HOST+url, {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
 body: JSON.stringify(params.data),
}).then(res=>res.json())

export const PUT = (url, params) => fetch(HOST+url, {
  method: 'PUT',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    'Authorization': 'JWT ' + params.token
  },
 body: JSON.stringify(params.data),
}).then(res=>res.json)


export const DELETE = (url, params) => fetch(HOST+url, {
  method: 'DELETE',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    'Authorization': 'JWT ' + params.token
  },
 body: JSON.stringify(params.data),
}).then(res=>res.json)